package book;

//选民投票Voter，每人只允许投票一次，当票数达到100时停止投票。
public class Voter {

		private static final int MAX_COUNT = 100; //总票数
		private static int count = 0; //记录投票数量
		
		private String name; //投票人姓名

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}
		
		//无参构造器
		public Voter() {
			
		}
		//有参构造器
		public Voter(String name) {
			this.setName(name);
		}
		
		//投票
		public void voting() {
			if(MAX_COUNT  == count) {
				System.out.println("投票活动已经结束！");
			}
			else {
				count++;
				System.out.println(this.getName() + "：感谢您投票！");
			}
		}
		
		//静态方法打印目前投票情况
		public static void print() {
			System.out.println("选民投票总数为:" + Voter.count + "票");
		}
		
		public static void main(String[] args) {
			print();
			
			Voter v1 = new Voter();
			v1.setName("James");
			v1.voting();
			
			
			Voter v2 = new Voter();
			v2.setName("Tom");
			v2.voting();
			
			
			Voter v3 = new Voter();
			v3.setName("Sam");
			v3.voting();
			
			for (int i = 1; i <= 98; i++) {
				Voter v = new Voter("user" + i);
				v.voting();
			}
			
			print();
		}

}
